﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Sendz.Domain
{
    // Todo: Need to decide if validation and data annotation should be at domain level or a metadata class in the MVC project
    public class Identity
    {
        // Entity
        [HiddenInput(DisplayValue=false)]
        public Guid IdentityKey { get; set; }

        [DisplayName("Email Address")]
        [Required(ErrorMessage = "An email address is required")]
        [RegularExpression(@"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$", ErrorMessage = "Please enter a valid email address")]
        [StringLength(100, ErrorMessage = "Please ensure that the email address you enter is less than 100 characters")]       
        public string Email { get; set; }

        [HiddenInput(DisplayValue = false)]
        public DateTime CreatedOn { get; set; }

        // Parents
        [HiddenInput(DisplayValue = false)]
        public Guid UserKey { get; set; }
        public User User { get; set; }

        // Children
        [HiddenInput(DisplayValue = false)]
        public List<Response> Responses { get; set; }
        [HiddenInput(DisplayValue = false)]
        public List<AutoResponse> AutoResponses { get; set; }

        // Constructors
        public Identity()
        {
            // Moved to a calculated column in the Entity Framework ORM (property StoreGeneratedPattern)
            // Ref: http://msdn.microsoft.com/en-us/library/ms189786.aspx
            // Ref: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/
            // this.IdentityKey = Guid.NewGuid();
            this.CreatedOn = DateTime.Now;
        }

        public Identity(Guid userKey, string email)
        {
            // Moved to a calculated column in the Entity Framework ORM (property StoreGeneratedPattern)
            // this.IdentityKey = Guid.NewGuid();
            this.UserKey = userKey;
            this.Email = email;
            this.CreatedOn = DateTime.Now;
        }
    }
}
